package DB;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectDBC {
    private static String USER = "root";
    private static String PASSWORD ="root";
    private static String DB_URL = "jdbc:mysql://localhost:3306/market?useUnicode=true&characterEncoding=utf8";
    private static String DB_DRIVER = "com.mysql.jdbc.Driver";
    private static Connection connection = null;

    public static Connection getConnection() {

       
        	try {
				Class.forName(DB_DRIVER);
				connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);
			} catch (ClassNotFoundException e) {
				 System.out.println("驱动没找到");
				e.printStackTrace();
			}catch (SQLException e) {
				  System.out.println("sql异常");
				e.printStackTrace();
			}
       
          
     
        return connection;
    }

    public  static void closeConnection(Connection connection){
        if(connection != null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
